<template>
    <div>
        <el-row :gutter="20">
            <el-col  class="label-tag" :span="2" v-for="label in labels" :key="label.id">
                <label-tag :label="label" :closeable="true"></label-tag>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="18" :offset="3">
                <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="pageInfo.page"
                    :page-sizes="pageInfo.sizes"
                    :page-size="pageInfo.size"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="pageInfo.total">
                </el-pagination>
            </el-col>
        </el-row>
    </div>
</template>

<script>
    import { mapActions } from 'vuex'
    import LabelTag from '@/components/label/LabelTag'

    export default {
        name: 'commonLabel',
        components: {
            LabelTag
        },
        data () {
            return {
                pageInfo: {
                    page: 1,
                    size: 20,
                    total: 0,
                    sizes: [20, 50, 100, 200, 300, 400]
                },
                labels: []
            }
        },
        mounted () {
            this.obtainLabels()
        },
        methods: {
            handleSizeChange (val) {
                this.pageInfo.size = val
                this.obtainLabels()
            },
            handleCurrentChange (val) {
                this.pageInfo.page = val
                this.obtainLabels()
            },
            ...mapActions('label', {
                pageLabelAction: 'pageLabel'
            }),
            obtainLabels () {
                this.action(this.pageLabelAction(this.pageInfo), data => {
                    this.labels = data.data.records
                    this.pageInfo.total = data.data.total
                    this.pageInfo.page = data.data.pages
                })
            }
        }
    }
</script>

<style lang="scss" scoped>
    .label-tag {
        margin: 10px 0;
    }
</style>
